package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.web.admin.mapper.FacilityInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.RoomFacility;
import com.atguigu.lease.web.admin.service.RoomFacilityService;
import com.atguigu.lease.web.admin.mapper.RoomFacilityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【room_facility(房间&配套关联表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class RoomFacilityServiceImpl extends ServiceImpl<RoomFacilityMapper, RoomFacility>
    implements RoomFacilityService{

    @Autowired
    private FacilityInfoMapper facilityInfoMapper;

    @Override
    public List<FacilityInfo> getRoomFacilityListById(Long id) {
        List<RoomFacility> roomFacilityList = super.list(new LambdaQueryWrapper<RoomFacility>().eq(RoomFacility::getRoomId, id));
        if (roomFacilityList == null || roomFacilityList.size() <= 0) {
            return null;
        }
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectList(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, roomFacilityList.stream().map(RoomFacility::getFacilityId).toList()));
        return facilityInfoList;
    }
}




